package com.e.library.entity;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.e.library.utils.EGsonUtils;

/**
 * Created by lxy on 2016/12/8.
 */

public class User implements Parcelable {


    /**
     * id : 4
     * headimgurl : /Static/Uploads/User/2017-03-18/58cce8a073e6a.jpeg
     * nickname : wugf@ewhale.cn
     */

    public String id;
    public String headimgurl;
    public String nickname;
    public String sex;
    public String username;
    public String phone;
    public String email;
    public String money;
    public String point;
    public String longitude;
    public String latitude;
    public String last_earning;
    public String all_earning;
    public String status;
    public String pay_password;

    /**------是否绑定facebook（0：否，1：是）-----**/
    public int facebook;
    public int wechat;

    public boolean isBindingFacebook(){
        return facebook == 1;
    }

    public boolean isBindingWechat(){
        return wechat == 1;
    }

    /**------username不为空，表示已绑定邮箱-----**/
    public boolean isBindingEmail(){
        return !TextUtils.isEmpty(username);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeString(this.headimgurl);
        dest.writeString(this.nickname);
        dest.writeString(this.sex);
        dest.writeString(this.username);
        dest.writeString(this.phone);
        dest.writeString(this.email);
        dest.writeString(this.money);
        dest.writeString(this.point);
        dest.writeString(this.longitude);
        dest.writeString(this.latitude);
        dest.writeString(this.last_earning);
        dest.writeString(this.all_earning);
        dest.writeString(this.status);
        dest.writeString(this.pay_password);
        dest.writeInt(this.facebook);
        dest.writeInt(this.wechat);
    }

    public User() {
    }

    protected User(Parcel in) {
        this.id = in.readString();
        this.headimgurl = in.readString();
        this.nickname = in.readString();
        this.sex = in.readString();
        this.username = in.readString();
        this.phone = in.readString();
        this.email = in.readString();
        this.money = in.readString();
        this.point = in.readString();
        this.longitude = in.readString();
        this.latitude = in.readString();
        this.last_earning = in.readString();
        this.all_earning = in.readString();
        this.status = in.readString();
        this.pay_password = in.readString();
        this.facebook = in.readInt();
        this.wechat = in.readInt();
    }

    public static final Parcelable.Creator<User> CREATOR = new Parcelable.Creator<User>() {
        @Override
        public User createFromParcel(Parcel source) {
            return new User(source);
        }

        @Override
        public User[] newArray(int size) {
            return new User[size];
        }
    };

    @Override
    public String toString() {
        return EGsonUtils.obj2Json(this);
    }
}
